﻿using ServerBase.Client;
using ServerBase.Other;
using ServerBase.Protocol;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using UtilPublic.ApiDispatcher;
using UtilPublic.Serialization;
using static ToolClient.DataClient;

namespace ToolClient
{
    /// <summary>
    /// PagePlayer.xaml 的交互逻辑
    /// </summary>
    public partial class PagePlayer : Page
    {
        public PagePlayer()
        {
            InitializeComponent();

            MainWindow.绑定控制器(this);
        }

        #region 信息
        public void SendInfoGetAll()
        {
            var Req = new C2G_Info_GetAll();
            App.ClientNetGame.Send(Req);
        }
        [ApiDpPro((short)EProtocolId.G2C_INFO_GETALL)]
        public short OnInfoGetAll()
        {
            var Rsp = LunarClientDispatcher.OnMsg.To<G2C_Info_GetAll>();
            if (Rsp.Success) { App.DebugDebug("G2C_Info_GetAll 成功"); } else { App.DebugError(Rsp.Result); return 1; }

            InfoBase = Rsp.InfoBase;
            InfoMisc = Rsp.InfoMisc;
            InfoGame = Rsp.InfoGame;

            UpdateInfoBase();
            UpdateInfoMisc();
            UpdateInfoGame();

            App.WdMain.Title = $"服务器ID:{InfoMisc.ServerConfigId} Uuid:{Uuid} Puid:{InfoBase.Puid} Name:{Name}";
            return 0;
        }
        [ApiDpPro((short)EProtocolId.G2C_INFO_PUSHALL)]
        public short OnInfoPushAll()
        {
            var Rsp = LunarClientDispatcher.OnMsg.To<G2C_Info_PushAll>();
            if (Rsp.Success) { App.DebugDebug("G2C_Info_GetAll 成功"); } else { App.DebugError(Rsp.Result); return 1; }

            InfoBase = Rsp.InfoBase;
            InfoMisc = Rsp.InfoMisc;
            InfoGame = Rsp.InfoGame;

            UpdateInfoBase();
            UpdateInfoMisc();
            UpdateInfoGame();
            return 0;
        }
        [ApiDpPro((short)EProtocolId.G2C_INFO_PUSHBASE)]
        public short OnInfoPushBase()
        {
            var Rsp = LunarClientDispatcher.OnMsg.To<G2C_Info_PushBase>();
            if (Rsp.Success) { App.DebugDebug("G2C_Info_GetBase 成功"); } else { App.DebugError(Rsp.Result); return 1; }

            InfoBase = Rsp.InfoBase;
            InfoMisc = Rsp.InfoMisc;

            UpdateInfoBase();
            UpdateInfoMisc();
            return 0;
        }
        public void UpdateInfoBase()
        {
            BasePropMgr.GetFieldsDescList(InfoBase, out var ListDatas);
            DataGridInfoBase.BindingObj(ListDatas);
        }
        public void UpdateInfoMisc()
        {
            BasePropMgr.GetFieldsDescList(InfoMisc, out var ListDatas);
            DataGridInfoMisc.BindingObj(ListDatas);

            DataGridInfoMiscDictFlagInt.BindingDictObj(InfoMisc.DictFlagInt.ToDictionary(it => (EFlagInt)it.Key, it => it.Value));
            DataGridInfoMiscDictFlagBool.BindingDictObj(InfoMisc.DictFlagBool.ToDictionary(it => (EFlagBool)it.Key, it => it.Value));
            DataGridInfoMiscDictFlagClient.BindingDictObj(InfoMisc.DictFlagClient);
            DataGridInfoMiscDictFlagClientDaily.BindingDictObj(InfoMisc.DictFlagClientDaily);
        }
        public void UpdateInfoGame()
        {
            BasePropMgr.GetFieldsDescList(InfoGame, out var ListDatas);
            DataGridInfoGame.BindingObj(ListDatas);
        }
        #endregion
    }
}
